﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WcfClientTemplates.Templates;
using Raona.Code.Model;
using WcfClientTemplates.Test.Util;

namespace WcfClientTemplates.Test
{

    /// <summary>
    /// Summary description for ProxiesTest
    /// </summary>
    [TestClass]
    public class ProxiesTest
    {
        #region Generation Parameter (Private)

        private const string SPECIFIC_USINGS = @"
using AirProducts.Entities.Healthcare.General;
using AirProducts.Entities.Healthcare.Patients;
using AirProducts.Entities.Healthcare.Persons;
using AirProducts.Entities.Healthcare.Treatments;
using AirProducts.Entities.Healthcare.Users;
";
        private const string NAMESPACE_1 = "AirProducts.Services.Healthcare.Persons";
        private const string SERVICE_CONTRACT_NAMESPACE = "http://www.airproducts.com/services";
        private const string INTERFACE_1 = "IPatientService";
        private const string CLIENT_BASE_INTERFACE_NAME = "AdS.UI.Library.ServiceModel.ClientBase";

        #endregion

        public ProxiesTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void ProxyWithOneMethod()
        {
            string result1 = null;
            string result2 = null;

            Proxies proxies = new Proxies();
            ProxiesUsings proxiesUsings = new ProxiesUsings();

            proxiesUsings.SpecificUsings = ProxiesTest.SPECIFIC_USINGS;

            Namespace ns = new Namespace { Name = ProxiesTest.NAMESPACE_1 };
            proxies.Namespaces = new Namespace[] { ns };
            proxiesUsings.Namespaces = proxies.Namespaces;

            Interface itf = new Interface { Name = ProxiesTest.INTERFACE_1, ServiceContractNamespace = ProxiesTest.SERVICE_CONTRACT_NAMESPACE, ClientBaseName = ProxiesTest.CLIENT_BASE_INTERFACE_NAME };
            Method method = new Method { Name = "GetPatients", OverloadedName = "GetPatients1", ReturnType = "Raona.QueryResult<AirProducts.Entities.Healthcare.Patients.PatientCollection>" };
            Parameter[] parameters = new Parameter[] {
                new Parameter { Name = "properties", Type = "Raona.EntityModel.PropertyCollection" },
                new Parameter { Name = "filter", Type = "Raona.EntityModel.FilterCollection" },
                new Parameter { Name = "order", Type = "Raona.EntityModel.OrderCollection" },
                new Parameter { Name = "pageInfo", Type = "Raona.PageInfo" },
                new Parameter { Name = "logInfo", Type = "Raona.Logs.LogInfo" }
            };
            method.Parameters = new List<Parameter>(parameters);
            itf.AddMethod(method);
            ns.Interfaces = new List<Interface>(new Interface[] { itf });

            result1 = proxiesUsings.TransformText();
            result2 = proxies.TransformText();

            ResultsHelper.AreEqual("ProxyWithOneMethod", result1 + result2);
        }
    }
}
